#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

int list[2001];
int dp[1001][2001];

int main()
{
    int k, n;
    while (cin >> n >> k)
    {
        for (int i = 1; i <= n; i++)
            cin >> list[i];
        sort(list + 1, list + 1 + n);

        for (int i = 1; i <= n; i++)
            dp[0][i] = 0;
        for (int i = 1; i <= k; i++)
        {
            for (int j = 2 * i; j <= n; j++)
            {
                if (j > 2 * i)
                    dp[i][j] = dp[i][j - 1];
                else
                    dp[i][j] = 100000;
                if (dp[i][j] > dp[i - 1][j - 2] + (list[j] - list[j - 1]) * (list[j] - list[j - 1]))
                    dp[i][j] = dp[i - 1][j - 2] + (list[j] - list[j - 1]) * (list[j] - list[j - 1]);
            }
        }
        cout << dp[k][n] << endl;
    }
    return 0;
}